package com.ruoyi.web.controller.rgpp;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rgpp.domain.JmrzpCompany;
import com.ruoyi.rgpp.service.IJmrzpCompanyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业招聘Controller
 * 
 * @author ruoyi
 * @date 2022-06-15
 */
@Controller
@RequestMapping("/rgpp/jmrzpcompany")
public class JmrzpCompanyController extends BaseController
{
    private String prefix = "rgpp/jmrzpcompany";

    @Autowired
    private IJmrzpCompanyService jmrzpCompanyService;

    @RequiresPermissions("rgpp:jmrzpcompany:view")
    @GetMapping()
    public String jmrzpcompany()
    {
        return prefix + "/jmrzpcompany";
    }

    /**
     * 查询企业招聘列表
     */
    @RequiresPermissions("rgpp:jmrzpcompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JmrzpCompany jmrzpCompany)
    {
//        startPage();
////        List<JmrzpCompany> list = jmrzpCompanyService.selectJmrzpCompanyList(jmrzpCompany);
////        return getDataTable(list);
        SysUser user = getSysUser();
        String sPhone=user.getLoginName();
        List<JmrzpCompany> list=new ArrayList<>();
        if (user.getUserId()==1){
            startPage();
            list = jmrzpCompanyService.selectJmrzpCompanyList(jmrzpCompany);

        }else {
            jmrzpCompany.setCard(sPhone);
            startPage();
            list=jmrzpCompanyService.selectJmrzpCompanyList(jmrzpCompany);
        }
        return getDataTable(list);
    }

    /**
     * 导出企业招聘列表
     */
    @RequiresPermissions("rgpp:jmrzpcompany:export")
    @Log(title = "企业招聘", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmrzpCompany jmrzpCompany)
    {
        List<JmrzpCompany> list = jmrzpCompanyService.selectJmrzpCompanyList(jmrzpCompany);
        ExcelUtil<JmrzpCompany> util = new ExcelUtil<JmrzpCompany>(JmrzpCompany.class);
        return util.exportExcel(list, "企业招聘数据");
    }

    /**
     * 新增企业招聘
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存企业招聘
     */
    @RequiresPermissions("rgpp:jmrzpcompany:add")
    @Log(title = "企业招聘", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JmrzpCompany jmrzpCompany)
    {
        return toAjax(jmrzpCompanyService.insertJmrzpCompany(jmrzpCompany));
    }

    /**
     * 修改企业招聘
     */
    @RequiresPermissions("rgpp:jmrzpcompany:edit")
    @GetMapping("/edit/{card}")
    public String edit(@PathVariable("card") String card, ModelMap mmap)
    {
        JmrzpCompany jmrzpCompany = jmrzpCompanyService.selectJmrzpCompanyByCard(card);
        mmap.put("jmrzpCompany", jmrzpCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存企业招聘
     */
    @RequiresPermissions("rgpp:jmrzpcompany:edit")
    @Log(title = "企业招聘", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JmrzpCompany jmrzpCompany)
    {
        return toAjax(jmrzpCompanyService.updateJmrzpCompany(jmrzpCompany));
    }

    /**
     * 删除企业招聘
     */
    @RequiresPermissions("rgpp:jmrzpcompany:remove")
    @Log(title = "企业招聘", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jmrzpCompanyService.deleteJmrzpCompanyByCards(ids));
    }
}
